FROM debian:stretch

MAINTAINER <yiane@qq.com>

USER root

# 切换阿里源
ARG CHANGE_SOURCE=false
RUN if [ ${CHANGE_SOURCE} = true ]; then \
echo \
"deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib\n\
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib\n\
deb http://mirrors.aliyun.com/debian-security stretch/updates main\n\
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main\n\
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib\n\
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib\n\
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib\n\
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib\n" > /etc/apt/sources.list \
;fi

###########################################################################
# Add a non-root user to prevent files being created with root permissions on host machine.
###########################################################################
ARG PUID=1000
ENV PUID ${PUID}
ARG PGID=1000
ENV PGID ${PGID}

###########################################################################
# Set Timezone
###########################################################################

ARG TZ=UTC
ENV TZ ${TZ}

RUN set -x \
    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && echo $TZ > /etc/timezone && \
    groupadd -g ${PGID} www && \
    # useradd -u ${PUID} -g www -m www -G wheel && \
    useradd -u ${PUID} -g www -m www -s /bin/bash

RUN set -x \
    && apt-get update \
    && apt-get install --no-install-recommends --no-install-suggests -y gcc automake autoconf libtool make gcc \
    curl \
    wget \
    vim \
    openssl libssl-dev \
    libpcre3 libpcre3-dev \
    make \
    zlib1g-dev \
    apt-utils \
    inetutils-ping \
    libzip-dev zip unzip

WORKDIR /tmp

ADD http://tengine.taobao.org/download/tengine-2.3.1.tar.gz tengine.tar.gz

RUN tar -zxvf tengine.tar.gz \
    && cd tengine-2.3.1  \
    && ./configure \
        --prefix=/usr/local/tengine \
#        --with-syslog \
        --with-stream_realip_module \
        --with-http_v2_module \
        --add-module=./modules/ngx_http_proxy_connect_module \
        --add-module=./modules/ngx_http_concat_module \
        --add-module=./modules/ngx_http_user_agent_module \
        --add-module=./modules/ngx_http_sysguard_module \
        --add-module=./modules/ngx_http_upstream_dynamic_module \
        --add-module=./modules/ngx_http_upstream_dyups_module \
    && make  \
    && make install \
    && cd /tmp && rm -rf ./*
#USER www

COPY ./conf/nginx.conf /usr/local/tengine/conf/nginx.conf

CMD ["/usr/local/tengine/sbin/nginx", "-g", "daemon off;"]
